import apiClient from '@/api/apiClient.ts';
import { AlarmCount, AlarmDeal, AlarmTime, AlarmTrend, DeviceCount, Equipment } from '#/entity.ts';

export enum IotServicesApi {
  GetAlarmCount = '/roadCure/videoMonitor/getAlarmCount',
  GetAlarmCountByCondition = '/roadCure/videoMonitor/getAlarmCountByCondition',
  GetAlarmDeal = '/roadCure/videoMonitor/getAlarmDeal',
  GetAlarmTrend = '/roadCure/videoMonitor/getAlarmTrend',
  GetDeviceCount = '/roadCure/videoMonitor/getDeviceCount',
  GetEquipmentList = '/roadCure/videoMonitor/getEquipmentList',
  GetEventCenterList = '/roadCure/videoMonitor/getEventCenterList',
}

interface GetAlarmCountParams {
  order: string;
  carNo?: string;
  serialNumber?: string;
}

const getAlarmCount = (data?: Omit<GetAlarmCountParams, 'order'>) =>
  apiClient.post<AlarmCount>({
    url: IotServicesApi.GetAlarmCount,
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });

const getAlarmCountByCondition = (data: GetAlarmCountParams) =>
  apiClient.post<AlarmTime>({
    url: IotServicesApi.GetAlarmCountByCondition,
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });

const getAlarmDeal = (data: GetAlarmCountParams) =>
  apiClient.post<AlarmDeal>({
    url: IotServicesApi.GetAlarmDeal,
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });

const getAlarmTrend = (data: Omit<GetAlarmCountParams, 'order'>) =>
  apiClient.post<AlarmTrend[]>({
    url: IotServicesApi.GetAlarmTrend,
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });

const getDeviceCount = (data?: Omit<GetAlarmCountParams, 'order'>) =>
  apiClient.post<DeviceCount>({
    url: IotServicesApi.GetDeviceCount,
    data: data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });

const getEquipmentList = (data: { carNo: string }) =>
  apiClient.post<Equipment[]>({
    url: IotServicesApi.GetEquipmentList,
    data,
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
  });

export default {
  getAlarmCount,
  getAlarmCountByCondition,
  getAlarmDeal,
  getAlarmTrend,
  getDeviceCount,
  getEquipmentList,
};
